package com.whiteape.book.model.dto;

import com.whiteape.book.model.bo.BaseMediaInfoBean;
import com.whiteape.book.utils.GsonUtils;
import com.whiteape.book.utils.MapConverter;

import org.greenrobot.greendao.annotation.Convert;
import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.Index;
import org.greenrobot.greendao.annotation.Transient;
import org.greenrobot.greendao.converter.PropertyConverter;

import java.io.Serializable;
import java.util.HashMap;
import org.greenrobot.greendao.annotation.Generated;

@Entity
public class SiteSourceHomepageBean extends BaseMediaInfoBean implements PropertyConverter<SiteSourceHomepageBean, String>, Serializable {

    public static final long serialVersionUID = 11111122349603L;

    //用 md5(siteHostUrl + headName + title)生成的唯一id
    @Id
    private String id;
    @Index
    private String siteHostUrl;
    //头部名字，就是首页中某一部分模块的名字，比如：重磅推荐/奇幻言情等等
    private String headName;
    //更新日期，尽量每天都更新，如果没有就用数据库中已存在的
    private String updateTime;
    //详情页url
    private String detailUrl;

    @Transient
    private SiteSourceBean siteSourceBean;

    @Convert(columnType = String.class, converter = MapConverter.class)
    private HashMap<String, String> varMap;


    @Generated(hash = 636379914)
    public SiteSourceHomepageBean(String id, String siteHostUrl, String headName, String updateTime, String detailUrl,
            HashMap<String, String> varMap) {
        this.id = id;
        this.siteHostUrl = siteHostUrl;
        this.headName = headName;
        this.updateTime = updateTime;
        this.detailUrl = detailUrl;
        this.varMap = varMap;
    }

    @Generated(hash = 694205575)
    public SiteSourceHomepageBean() {
    }


    @Override
    public SiteSourceHomepageBean convertToEntityProperty(String databaseValue) {
        return GsonUtils.string2Obj(databaseValue, SiteSourceHomepageBean.class);
    }

    @Override
    public String convertToDatabaseValue(SiteSourceHomepageBean entityProperty) {
        return GsonUtils.obj2String(entityProperty);
    }

    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public String getSiteHostUrl() {
        return siteHostUrl;
    }

    public void setSiteHostUrl(String siteHostUrl) {
        this.siteHostUrl = siteHostUrl;
    }

    public String getHeadName() {
        return headName;
    }

    public void setHeadName(String headName) {
        this.headName = headName;
    }

    public String getUpdateTime() {
        return updateTime;
    }

    public void setUpdateTime(String updateTime) {
        this.updateTime = updateTime;
    }

    public HashMap<String, String> getVarMap() {
        return varMap;
    }

    public void setVarMap(HashMap<String, String> varMap) {
        this.varMap = varMap;
    }

    public String getDetailUrl() {
        return detailUrl;
    }

    public void setDetailUrl(String detailUrl) {
        this.detailUrl = detailUrl;
    }

    public SiteSourceBean getSiteSourceBean() {
        return siteSourceBean;
    }

    public void setSiteSourceBean(SiteSourceBean siteSourceBean) {
        this.siteSourceBean = siteSourceBean;
    }

    @Override
    public String toString() {
        return "SiteSourceHomepageBean{" +
                "id='" + id + '\'' +
                ", siteHostUrl='" + siteHostUrl + '\'' +
                ", headName='" + headName + '\'' +
                ", updateTime='" + updateTime + '\'' +
                ", detailUrl='" + detailUrl + '\'' +
                ", varMap=" + varMap +
                ", mediaType=" + mediaType +
                ", title='" + title + '\'' +
                ", author='" + author + '\'' +
                ", coverUrl='" + coverUrl + '\'' +
                ", desc='" + desc + '\'' +
                ", wordCount='" + wordCount + '\'' +
                ", state='" + state + '\'' +
                ", category='" + category + '\'' +
                ", lastChapter='" + lastChapter + '\'' +
                ", lastUpdated='" + lastUpdated + '\'' +
                '}';
    }
}
